import annation.CacheMap;
import utils.PackageUtil;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;

/**
 * @author zsy
 * @Description:
 * @create 2018-01-07 21:15
 **/
public class InjectionFactory {
    public void injection(Map<Class, Map> objectMap) throws IllegalAccessException {
        List<Class<?>> cache = PackageUtil.getClasses("cache");
        for (Class<?> item : cache) {
            for (Field field : item.getDeclaredFields()) {
                field.setAccessible(true);
                if (field.isAnnotationPresent(CacheMap.class)) {
                    CacheMap annotation = field.getAnnotation(CacheMap.class);
                    Class classKey = annotation.value();
                    field.set(null, objectMap.get(classKey));
                }
            }
        }

    }
}
